package com.liuyu.common.framework.iinsure.adapter.pc.admin.allowlist.web

import com.alibaba.fastjson.JSON
import com.baomidou.mybatisplus.core.metadata.IPage
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.liuyu.common.framework.iinsure.ApplicationTests
import com.liuyu.common.framework.iinsure.allowlist.service.facade.AllowListService
import com.liuyu.common.framework.mybatis.iinsure.query.OpenAllowListQuery
import com.liuyu.common.framework.mybatis.iinsure.vo.OpenAllowListVO
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.http.MediaType
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
import org.springframework.test.web.servlet.result.MockMvcResultMatchers
import spock.lang.Specification
import spock.lang.Title

/**
 * ${DESCRIPTION}
 * @author: liuyu
 * @date: 2023/5/17 12:44
 * @version: ${VERSION}
 */
@Title("AdminAllowListController 单元测试")
@SpringBootTest(classes = ApplicationTests)
@AutoConfigureMockMvc
@WebMvcTest(controllers = AdminAllowListController.class)
class AdminAllowListControllerTest extends Specification {
    @Autowired
    private MockMvc mvc

    @Autowired
    AllowListService allowListService;

    def setup() {
        IPage<OpenAllowListVO> list = new Page<>(0, 10)
        List<OpenAllowListVO> allowListVOList = new ArrayList<>()
        allowListVOList.add(new OpenAllowListVO())
        list.setRecords(allowListVOList)
        allowListService.listAllowList >> list
    }


    def "ListInvoice"() {
        given:
        def params = new OpenAllowListQuery()
        params.setStart(0)
        params.setLimit(10)
        expect:

        String result = mvc.perform(MockMvcRequestBuilders.post("/admin/allow/list")
                .contentType(MediaType.APPLICATION_JSON).content(JSON.toJSONString(params)))
                .andExpect(MockMvcResultMatchers.status().isOk())

    }

    def "SaveAllowList"() {}
}
